<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>demo-管理系统</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" th:href="@{/css/bootstrap.css}">
    <link rel="stylesheet" th:href="@{/css/dashboard.css}">
    <style type="text/css">
        body{
            background-color: #f5f5f5;
            padding-top: 55px;
        }
        html {
            overflow-y: scroll;
        }
        :root {
            overflow-y: auto;
            overflow-x: hidden;
        }
        :root body {
            position: absolute;
        }
        body {
            width: 100vw;
            overflow: hidden;
        }
    </style>
    <script th:src="@{/js/jquery-3.4.1.min.js}"></script>
    <script th:src="@{/js/bootstrap.bundle.min.js}"></script>
</head>
<body>
<div class="container-fluid">
    <div class="row">
        <div th:include="layout/left :: left(user=${session.admin},flag=${session.admin}!=null,page='news_manage')"></div>
        <main class="col-10 ml-auto px-4 mt-4">
            <div class="col-12 mb-3 pb-3 border-bottom border-gray">
                <h2>新增新闻</h2>
            </div>
            <div>
                <form class="col-10 mx-auto" role="form" th:action="@{addNews.do}" th:method="POST">
                    <div class="form-group mb-4 d-flex justify-content-start">
                        <div class="media">
                            <h6 class="align-self-center ml-auto">标题：</h6>
                        </div>
                        <div class="col-11">
                            <label for="title" class="sr-only">标题</label>
                            <input type="text" name="title" class="form-control" id="title" required
                                   data-toggle="tooltip" title="最多32个字符" data-placement="right" data-trigger="manual">
                        </div>
                    </div>
                    <div class="form-group mb-4 d-flex justify-content-start">
                        <div class="media align-self-start pt-1">
                            <h6 class="align-self-center ml-auto">正文：</h6>
                        </div>
                        <div class="col-11">
                            <label for="content" class="sr-only">正文</label>
                            <textarea class="form-control" id="content" name="content" rows="10" required></textarea>
                            <p class="text-muted my-0 float-right" id="word">5000</p>
                        </div>
                    </div>
                    <div class="mb-4 d-flex justify-content-center">
                        <button class="btn btn-danger col-2 mr-5" type="submit">提交</button>
                        <button class="btn btn-secondary col-2" type="reset" id="cancel">取消</button>
                    </div>
                </form>
            </div>
            <div th:include="layout/footer :: Footer"></div>
        </main>
    </div>
</div>

<script type="text/javascript">
    $('textarea').each(function () {
        this.setAttribute('style', 'height:' + (this.scrollHeight) + 'px;overflow-y:hidden;');
    }).on('input', function () {
        this.style.height = 'auto';
        this.style.height = (this.scrollHeight) + 'px';
    });
    $("#title").keyup(function(){
        let len = $(this).val().length;
        if(len > 31){
            $(this).val($(this).val().substring(0,32));
            $(this).tooltip('show');
            setTimeout(function(){
                $("#title").tooltip('hide');
            }, 2000);
        }
    });
    $("#content").keyup(function(){
        let len = $(this).val().length;
        if(len > 4999){
            $(this).val($(this).val().substring(0,5000));
        }
        if(len <= 0){
            $("#word").text("0/5000");
        }else if(len >= 5000){
            $("#word").text('5000/5000');
        }else
        {
            $("#word").text(len+'/5000');
        }
    });
    // $("form").submit(function(){
    //     window.history.back();
    //     return false;
    // });
    $("#cancel").click(function(){
        window.history.back();
    });
</script>
</body>
</html>